//
//  PersonCenterController.m
//  BigToBig
//
//  Created by guochuangkeshi on 16/4/22.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "PersonCenterController.h"
#import "SignButton.h"
#import "TicketController.h"
#import "SettingController.h"
#import "BasicInformationViewController.h"
#import "LoginModel.h"
#import "ProjectInfoViewController.h"
#import <CommonCrypto/CommonDigest.h>
#import "ShenqingRZViewController.h"
#import "RoadShowViewController.h"
#import "AMatchViewController.h"
#import "IncubationSpaceMessageController.h"
#import "HomeController.h"
#import "CreateProjectViewController.h"
#import "MessageServiceProviderChooseCell.h"
#import "MessageServiceProviderController.h"



@interface PersonCenterController ()<UITableViewDelegate,UITableViewDataSource>
{
    UIView *backV;
    UIButton *imageV;
    UIImage *changeIconImage;
}

@property(nonatomic,strong)NSMutableArray *nameArr;
@property(nonatomic,strong)NSMutableArray *imageArr;
@property(nonatomic,strong)NSMutableArray *twoNameArr;
@property(nonatomic,strong)NSMutableArray *twoImageArr;
@property(nonatomic,strong)NSMutableArray *personArray;
@property(nonatomic,weak)UIImage *savedImage;
@property (nonatomic ,weak)UIButton *signBtn;
@property (nonatomic ,copy)NSString *fensiCount;
@property (nonatomic ,copy)NSString *guanzhuCount;
@property (nonatomic ,weak)UILabel *fanLab;
@property (nonatomic ,weak)UILabel *guanzhuLab;
@property (nonatomic ,weak)NSNotificationCenter *notificationCenter;
@property(nonatomic,copy)NSString *useType;
@property(nonatomic,strong)UITableView *tableView;
@end

@implementation PersonCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSNotificationCenter * notificationCenter = [ NSNotificationCenter defaultCenter];
    self.notificationCenter = notificationCenter;
    [notificationCenter addObserver:self selector:@selector(changeIconImage:) name:@"AnyNotification" object:nil];
    
    self.tabBarController.tabBar.hidden = NO;
    
    [self addTouxiangView];
    
    [self addTableview];
    
    [self loadQianDao];

    [self fensiLoad];
    [self guanzhuLoad];
    [self userTypeConfirm];
//    NSLog(@"%@",self.MessageDict);
}

#pragma mark 确定用户类型

- (void)userTypeConfirm{

    NSUserDefaults* inputNub = [NSUserDefaults standardUserDefaults];
    NSString *inputNumber = [inputNub objectForKey:@"InputNub"];
    NSUserDefaults* inputSecrte = [NSUserDefaults standardUserDefaults];
    NSString *inputSecrete = [inputSecrte objectForKey:@"Secreate"];
    
    NSDictionary *params = @{@"username":inputNumber,@"password":inputSecrete};
    
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/user/login?" params:params success:^(id json) {
//        NSLog(@"%@",json);
    
        self.useType = [NSString stringWithFormat:@"%@",json[@"user_type"]];
      
            if ([self.useType isEqualToString:@"1"]) {
                self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"创建项目",@"我的消息", nil];
            }else if ([self.useType isEqualToString:@"2"]) {
                self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"发起速配",@"我的消息", nil];
            }else if ([self.useType isEqualToString:@"3"]){
                self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"我的消息", nil];
            }else if ([self.useType isEqualToString:@"4"]){
                 self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"我的消息", nil];
            }else if ([self.useType isEqualToString:@"5"]){
                 self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"我的消息", nil];
            }else if ([self.useType isEqualToString:@"6"]){
                 self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"我的消息", nil];
            }
            else{
                 self.nameArr = [[NSMutableArray alloc] initWithObjects:@"我的秀券",@"路演&速配",@"申请认证",@"我的消息", nil];
            }

                if ([self.useType isEqualToString:@"1"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-14",@"组-16", nil];
                }else if ([self.useType isEqualToString:@"2"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"发起速配",@"组-16", nil];
                }else if ([self.useType isEqualToString:@"3"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-16", nil];
                }else if ([self.useType isEqualToString:@"4"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-16", nil];
                }else if ([self.useType isEqualToString:@"5"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-16", nil];
                }else if ([self.useType isEqualToString:@"6"]) {
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-16", nil];
                }
                else{
                    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"组-15",@"多边形-3",@"组-14",@"组-16", nil];
                }

        
            if (self.twoNameArr==nil) {
                if ([self.useType isEqualToString:@"1"]) {
                   self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"基本信息",@"设置", nil];
                }else if ([self.useType isEqualToString:@"2"]) {
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"投资人认证信息",@"基本信息",@"设置", nil];
                }else if ([self.useType isEqualToString:@"3"]) {
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"伙伴认证信息",@"基本信息",@"设置", nil];
                }else if ([self.useType isEqualToString:@"4"]) {
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"导师认证信息",@"基本信息",@"设置", nil];
                }else if ([self.useType isEqualToString:@"5"]) {
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"孵化空间认证信息",@"孵化空间信息",@"基本信息",@"设置", nil];
                }else if ([self.useType isEqualToString:@"6"]) {
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"信息服务认证信息",@"服务信息设置",@"基本信息",@"设置", nil];
                }
                else{
                    self.twoNameArr=[[NSMutableArray alloc] initWithObjects:@"基本信息",@"设置", nil];
                }
                
            }
        
            if (self.twoImageArr == nil) {
                if ([self.useType isEqualToString:@"1"]){
                    self.twoImageArr = [[NSMutableArray alloc] initWithObjects:@"组-17",@"组-18", nil];
                }else if ([self.useType isEqualToString:@"2"]){
                    self.twoImageArr = [[NSMutableArray alloc] initWithObjects:@"认证信息",@"组-17",@"组-18", nil];
                }else if ([self.useType isEqualToString:@"3"]){
                    self.twoImageArr = @[@"认证信息",@"组-17",@"组-18"].mutableCopy;
                }else if ([self.useType isEqualToString:@"4"]){
                    self.twoImageArr = @[@"认证信息",@"组-17",@"组-18"].mutableCopy;
                }else if ([self.useType isEqualToString:@"5"]){
                    self.twoImageArr = @[@"认证信息",@"孵化空间信息",@"组-17",@"组-18"].mutableCopy;
                }else if ([self.useType isEqualToString:@"6"]){
                    self.twoImageArr = @[@"认证信息",@"服务信息设置",@"组-17",@"组-18"].mutableCopy;
                }
                else{
                    self.twoImageArr = @[@"组-17",@"组-18"].mutableCopy;
                }
            }

        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
    
    }];

    
}


#pragma mark 粉丝l
- (void)fensiLoad{

    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    
    NSDictionary *params = @{@"id":UID};
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/relation/count_followers?" params:params success:^(id json) {
        
        self.fensiCount = [NSString stringWithFormat:@"%@",json[@"count"]];
        NSString *fensiShu = [NSString stringWithFormat:@"粉丝 : %@",self.fensiCount];
        self.fanLab.text = fensiShu;
//        NSLog(@"--------%@",self.fensiCount);
        

    } failure:^(NSError *error) {
        
        
    }];
}

#pragma mark 关注
- (void)guanzhuLoad{

    
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    

    NSDictionary *params = @{@"id":UID};
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/relation/count_followings?" params:params success:^(id json) {
        
        self.guanzhuCount = [NSString stringWithFormat:@"%@",json[@"count"]];
        NSString *guanzhuShu = [NSString stringWithFormat:@"关注 : %@",self.guanzhuCount];
        self.guanzhuLab.text = guanzhuShu;
  //        NSLog(@"%@",json[@"count"]);
        
    } failure:^(NSError *error) {
        
        
    }];
}

#pragma mark 签到
- (void)loadQianDao{


    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    
    NSDictionary *params = @{@"user_id":UID};
    
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/ticket/get_signin_status?" params:params success:^(id json) {
//        NSLog(@"------------------%@",json);
        
        NSString *QiandaoStatue = [NSString stringWithFormat:@"%@",json[@"return_code"]];
        
        if ([QiandaoStatue isEqualToString:@"24001"]) {
            
            [self.signBtn setTitle:@"已签到" forState:UIControlStateDisabled];
            
            [self.signBtn setEnabled:NO];
            
        }
        if ([QiandaoStatue isEqualToString:@"24002"]) {
            
            [self.signBtn setTitle:@"签到" forState:UIControlStateDisabled];
            
            [self.signBtn setEnabled:YES];
        }
        
    } failure:^(NSError *error) {
        
   
    }];
    

}

#pragma mark 更换头像
- (void)changeIconImage:(NSNotification *)text{

    UIImage *image =  [text.userInfo objectForKey:@"saveImage"];
    [imageV setImage:image forState:UIControlStateNormal];
    
    self.savedImage = image;

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    
}

#define mark 添加头像
- (void)addTouxiangView{
    
    backV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 175)];
    
    backV.backgroundColor=COLOR_RGBA(88, 165, 255, 1.0);
    
    [self.view addSubview:backV];

    //加载首先访问本地沙盒是否存在相关图片


    imageV=[[UIButton alloc]initWithFrame:CGRectMake(30, (backV.height-60)/2, 60, 60)];
    
//    NSUserDefaults *UserID = [NSUserDefaults standardUserDefaults];
//    NSString *UID = [UserID objectForKey:@"userID"];
//    
//    NSString *uidStr = [NSString stringWithFormat:@"%@",UID];
//    
//    NSString *str1 = [self md5HexDigest:uidStr];
//    
//    NSString *b = [str1 substringWithRange:NSMakeRange(8,16)];
//    NSString *str2 = @".png";
//    NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str2];
    //加载首先访问本地沙盒是否存在相关图片
//    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imgName];
//    NSLog(@"%@",fullPath);
//    UIImage *savedImage = [UIImage imageWithContentsOfFile:fullPath];
    
//    NSLog(@"%@",fullPath);
    
//    if (savedImage)    
//    {
    
//        [imageV setImage:savedImage forState:UIControlStateNormal];
//        self.savedImage =  savedImage;
//    }
//    else
//    {
        
        NSUserDefaults *UserID = [NSUserDefaults standardUserDefaults];
        NSString *UID = [UserID objectForKey:@"userID"];
        
        NSString *uidStr = [NSString stringWithFormat:@"%@",UID];
        
        NSString *str1 = [self md5HexDigest:uidStr];
        
        NSString *b = [str1 substringWithRange:NSMakeRange(8,16)];
        NSString *str2 = @".png";
        NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str2];
        NSString *str = [NSString stringWithFormat:@"http://61.135.176.43:6080/data/HeadPortrait/%@",imgName];
    
        UIImageView *imageView1 = [[UIImageView alloc]init];

        [imageView1 sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        if (error) {
            
            UIImage *imageTX = [UIImage imageNamed:@"tx"];
            [imageV setImage:imageTX forState:UIControlStateNormal];
            
            self.savedImage = imageTX;
            
            return ;
        }
        //清缓存因为图片名称始终是一个更改头像的时候数据库中会进行替换但是由于缓存会显示之前的图片所有需要清缓存
        [[SDImageCache sharedImageCache] clearDisk];
        [imageV setImage:imageView1.image forState:UIControlStateNormal];
        self.savedImage = imageView1.image;
        
        [self saveImage:self.savedImage withName:imgName];
        


    }];
//        [imageView1 sd_setImageWithURL:[NSURL URLWithString:str] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            
//            NSLog(@"%@",error);
//            if (error) {
//                
//                UIImage *imageTX = [UIImage imageNamed:@"tx"];
//                [imageV setImage:imageTX forState:UIControlStateNormal];
//                
//                self.savedImage = imageTX;
//                
//                return ;
//            }
            //清缓存因为图片名称始终是一个更改头像的时候数据库中会进行替换但是由于缓存会显示之前的图片所有需要清缓存
//            [[SDImageCache sharedImageCache] clearDisk];
//            [imageV setImage:imageView1.image forState:UIControlStateNormal];
//            self.savedImage = imageView1.image;
//            
//            [self saveImage:self.savedImage withName:imgName];
//            
//        }];



    imageV.layer.masksToBounds = YES;
    imageV.layer.cornerRadius = imageV.frame.size.height / 2;
    imageV.contentMode = UIViewContentModeScaleToFill;
    [imageV addTarget:self action:@selector(ClickHead) forControlEvents:UIControlEventTouchUpInside];
    [backV addSubview:imageV];
    
    
    NSUserDefaults* userType = [NSUserDefaults standardUserDefaults];
    NSString *userTp = [userType objectForKey:@"userTyp"];
    NSInteger userTP = [userTp integerValue];
    
    UILabel *identityLab= [[UILabel alloc]initWithFrame:CGRectMake(imageV.x - 8, imageV.maxY+8, imageV.width + 15, 20)];
    identityLab.backgroundColor = [UIColor clearColor];
    identityLab.textAlignment = NSTextAlignmentCenter;
    identityLab.font = [UIFont systemFontOfSize:13];
    identityLab.textColor= [UIColor whiteColor];
    identityLab.layer.borderColor = [UIColor whiteColor].CGColor;
    identityLab.layer.borderWidth = 0.5;
    identityLab.layer.masksToBounds = YES;
    identityLab.layer.cornerRadius = 5.0;
    
    if (userTP == 0 ) {
        
        identityLab.text = @"未验证";

    }if (userTP == 1) {
        identityLab.text = @"创业者";

    }if (userTP == 2) {
        identityLab.text = @"投资者";

        
    }if (userTP == 3) {
        identityLab.text = @"创业伙伴";

        
    }if (userTP == 4) {
        identityLab.text = @"创业导师";

        
    }if (userTP == 5) {
        identityLab.text = @"资源公司";

    }if (userTP == 6) {
        identityLab.text = @"信息提供者";

        
    }if (userTP == -1) {
        identityLab.text = @"未审核";

        
    }if (userTP == -2) {
        identityLab.text = @"未审核";

        
    }if (userTP == -3) {
        identityLab.text = @"未审核";

        
    }if (userTP == -4) {
        identityLab.text = @"未审核";

        
    }if (userTP == -5) {
        identityLab.text = @"未审核";

        
    }if (userTP == -6) {
        identityLab.text = @"未审核";

        
    }
    [backV addSubview:identityLab];
    
    UILabel *userNameLab = [[UILabel alloc]initWithFrame:CGRectMake(imageV.maxX+15, imageV.y+10, kScreenWidth-imageV.maxX-10, 20)];
    userNameLab.textColor = [UIColor whiteColor];
    userNameLab.text = @"登录/注册";
    
    
    NSUserDefaults* isLogin = [NSUserDefaults standardUserDefaults];
    BOOL isLoginStatu = [isLogin boolForKey:@"isOn"];
    
    NSUserDefaults* name = [NSUserDefaults standardUserDefaults];
    NSString *userName = [name objectForKey:@"name"];
    

    if (isLoginStatu == YES) {
        
        userNameLab.text = userName;

    }else{
    
        userNameLab.text = @"未知";
    }
    [backV addSubview:userNameLab];
    
    UILabel *desLab = [[UILabel alloc]initWithFrame:CGRectMake(imageV.maxX+15, userNameLab.maxY + 10, kScreenWidth-imageV.maxX-10, 10)];
    desLab.textColor = [UIColor whiteColor];
    desLab.font = [UIFont systemFontOfSize:12];
    desLab.text = @"暂无简介";
    [backV addSubview:desLab];
    
    //粉丝图片
    UIImageView *fansPic = [[UIImageView alloc] initWithFrame:CGRectMake(imageV.maxX+18, desLab.maxY+20, 15, 13)];
    fansPic.image = [UIImage imageNamed:@"61-副本"];
    [backV addSubview:fansPic];
    
    UILabel *fanLab = [[UILabel alloc]initWithFrame:CGRectMake(fansPic.maxX+5, desLab.maxY+17, kScreenWidth-fansPic.maxX-10, 20)];
    fanLab.textColor = [UIColor whiteColor];
    fanLab.font = [UIFont systemFontOfSize:12];

    self.fanLab = fanLab;
//    fanLab.text = fensiShu;
    [backV addSubview:fanLab];
    
    //关注图片
    UIImageView *guanzhuPic = [[UIImageView alloc] initWithFrame:CGRectMake(fansPic.maxX+60, desLab.maxY+21, 15, 10)];
    guanzhuPic.image = [UIImage imageNamed:@"116-副本"];
    [backV addSubview:guanzhuPic];
    
    UILabel *guanzhuLab = [[UILabel alloc]initWithFrame:CGRectMake(guanzhuPic.maxX+5, desLab.maxY+17, kScreenWidth-guanzhuPic.maxX-10, 20)];
    guanzhuLab.textColor = [UIColor whiteColor];
    guanzhuLab.font = [UIFont systemFontOfSize:12];
    self.guanzhuLab = guanzhuLab;
    [backV addSubview:guanzhuLab];
    
    SignButton *signBtn = [SignButton buttonWithType:UIButtonTypeCustom];
    [signBtn setBackgroundImage:[UIImage imageNamed:@"签到"] forState:UIControlStateNormal];
    signBtn.adjustsImageWhenHighlighted = NO;
    [signBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    self.signBtn = signBtn;
    signBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [signBtn setTitle:@"签到" forState:UIControlStateNormal];
    [signBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [signBtn setFrame:CGRectMake(kScreenWidth - 70, 40, 60, 20)];
    [signBtn addTarget:self action:@selector(signClick:) forControlEvents:UIControlEventTouchUpInside];
    [backV addSubview:signBtn];
}

#pragma mark 保存头像
- (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
    //jpeg格式的图片转换成二进制进行存储
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.8);
    
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    
//    NSLog(@"%@",fullPath);
    
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

- (void)ClickHead{

    BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
    BasicVc.savedImage = self.savedImage;
    BasicVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:BasicVc animated:YES];
}

#pragma mark 添加tableView
- (void)addTableview{
    UITableView *tableV=[[UITableView alloc]initWithFrame:CGRectMake(0, backV.maxY, kScreenWidth, kScreenHeight - backV.maxY - 49) style:UITableViewStylePlain];
    tableV.dataSource = self;
    tableV.delegate  = self;
    tableV.rowHeight = 70 ;
    [self.view addSubview:tableV];

    tableV.bounces = NO;
    [tableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.tableView = tableV;
}

- (void)signClick:(SignButton *)btn{
    

    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    if (status == NotReachable) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请检查网络连接";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
        return;
        
    }
    
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];

      
        NSDictionary *params = @{@"user_id":UID,@"comment":@"签到"};
        
        [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/ticket/signin?" params:params success:^(id json) {
            
            NSString *qianDaoReturn = [NSString stringWithFormat:@"%@",json[@"return_code"]];
            
            if ([qianDaoReturn isEqualToString:@"0"]) {
                
                UIView *backgroundV=[[UIView alloc]initWithFrame:KeyWindow.bounds];
                
                UIImageView *signV = [[UIImageView alloc]initWithFrame:KeyWindow.bounds];
                signV.image = [UIImage imageNamed:@"未标题-1"];
                signV.contentMode = UIViewContentModeScaleAspectFill;
                [backgroundV addSubview:signV];
                
                [KeyWindow addSubview:backgroundV];
                
                UITapGestureRecognizer *tapGes=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapBackgroundV:)];
                [backgroundV addGestureRecognizer:tapGes];
                
                [btn setTitle:@"已签到" forState:UIControlStateDisabled];
                
                [btn setEnabled:NO];
                
            }
            
            
            if ([qianDaoReturn isEqualToString:@"24001"]) {
                
                [btn setTitle:@"已签到" forState:UIControlStateDisabled];
                
                [btn setEnabled:NO];

            }

        } failure:^(NSError *error) {
   
        }];
    
}

- (void)tapBackgroundV:(UITapGestureRecognizer *)ges{
    UIView *view = ges.view;
    [view removeFromSuperview];
}
#pragma mark 返回section个数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return _nameArr.count;
    }else{
        return _twoNameArr.count;
    }
}

#pragma mark 分区高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

#pragma mark 绘制cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.section == 0) {
            cell.textLabel.text = self.nameArr[indexPath.row];
        
            NSString *imageName = self.imageArr[indexPath.row];
        
            cell.imageView.image = [UIImage imageNamed:imageName];
    }else{
        cell.textLabel.text = self.twoNameArr[indexPath.row];
        NSString *twoImageName = self.twoImageArr[indexPath.row];
        
        cell.imageView.image = [UIImage imageNamed:twoImageName];
        
    }

    return cell;
}

#pragma mark tableView点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        //所有身份section0都是我的秀券
        if (indexPath.row==0) {
            
            TicketController * ticketVc=[[TicketController alloc]init];
            ticketVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:ticketVc animated:YES];

        }
        //所有身份section1都是路演&速配
        if (indexPath.row == 1) {
            RoadShowViewController *roadShowVC = [[RoadShowViewController alloc]init];
            roadShowVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController  pushViewController:roadShowVC animated:YES];
        }
        
        if (indexPath.row == 2) {
            //创业者是创建项目
            if ([self.useType isEqualToString:@"1"]) {
                CreateProjectViewController *createProVC = [[CreateProjectViewController alloc] init];
                createProVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController  pushViewController:createProVC animated:YES];
                
             //投资人是发起速配
            }else if ([self.useType isEqualToString:@"2"]){
               //  发起速配
                AMatchViewController *aMatchVC = [[AMatchViewController alloc] init];
                aMatchVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:aMatchVC animated:YES];
            //剩下的第三个都是我的消息
            }else if ([self.useType isEqualToString:@"3"]||[self.useType isEqualToString:@"4"]||[self.useType isEqualToString:@"5"]||[self.useType isEqualToString:@"6"]){
                NewsViewController *newVC = [[NewsViewController alloc] init];
                
                newVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:newVC animated:YES];
                
            }else{
                // 未申请身份应申请认证身份
                ShenqingRZViewController *personCC = [[ShenqingRZViewController alloc]init];
                personCC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:personCC animated:YES];
            }

            self.navigationController.navigationBar.translucent = NO;
            
        }
        //创业伙伴 创业导师 孵化空间 信息服务 只有三个
        if (indexPath.row == 3) {
            if ([self.useType isEqualToString:@"3"]||[self.useType isEqualToString:@"4"]||[self.useType isEqualToString:@"5"]||[self.useType isEqualToString:@"6"]){
               
                
            }else{
                NewsViewController *newVC = [[NewsViewController alloc] init];
                newVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:newVC animated:YES];
            }
        }
        
    }else{
        
        //投资人
        if ([self.useType isEqualToString:@"2"]) {
            
            if (indexPath.row == 0) {
                //投资人认证信息
                ShenqingInvestorsController *shenqingInvestorsController = [[ShenqingInvestorsController alloc]init];
                shenqingInvestorsController.hidesBottomBarWhenPushed = YES;                 [self.navigationController pushViewController:shenqingInvestorsController animated:YES];
                
            }else if (indexPath.row == 1) {
                //基本信息
                BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                BasicVc.savedImage = self.savedImage;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }else if (indexPath.row == 2) {
                //设置
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }

        }else if ([self.useType isEqualToString:@"3"]){
            
            if (indexPath.row == 0) {
                //创业伙伴认证信息
                CreateTeacherViewController *createTeacherVC = [[CreateTeacherViewController alloc]init];
                createTeacherVC.userType = @"创业伙伴";
                [self.navigationController pushViewController:createTeacherVC animated:YES];
                
            }else if (indexPath.row == 1) {
                //基本信息
                BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }else if (indexPath.row == 2) {
                //设置
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }
            
            
        }else if ([self.useType isEqualToString:@"4"]){
            
            if (indexPath.row == 0) {
                //创业导师认证信息
                CreateTeacherViewController *createTeacherVC = [[CreateTeacherViewController alloc]init];
                createTeacherVC.userType = @"创业导师";
                [self.navigationController pushViewController:createTeacherVC animated:YES];
                
            }else if (indexPath.row == 1) {
                //基本信息
                BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                BasicVc.savedImage = self.savedImage;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }else if (indexPath.row == 2) {
                //设置
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }
            
        }else if ([self.useType isEqualToString:@"5"]){
            
            if (indexPath.row == 0) {
                //孵化空间
                CreateShareIncubationSpaceController *createShareIncubationSpaceC = [[CreateShareIncubationSpaceController alloc]init];
                [self.navigationController pushViewController:createShareIncubationSpaceC animated:YES];
                
            }else if (indexPath.row == 1){
                IncubationSpaceMessageController *inVC = [[IncubationSpaceMessageController alloc] init];
                inVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:inVC animated:YES];
                
            }else if (indexPath.row == 2) {
                
                BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                BasicVc.savedImage = self.savedImage;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }else if (indexPath.row == 3) {
                
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }
            
            
        }else if ([self.useType isEqualToString:@"6"]){
            
            if (indexPath.row == 0) {
             //信息服务
                MessageServiceProviderController *messVC = [[MessageServiceProviderController alloc] init];
                messVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:messVC animated:YES];
            }else if (indexPath.row == 1){
                
                
            }else if (indexPath.row == 2) {
                
                BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                BasicVc.savedImage = self.savedImage;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }else if (indexPath.row == 3) {
                
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }
            
            
        }else{
            //创业者.未认证
            if (indexPath.row==0) {
               BasicInformationViewController * BasicVc=[[BasicInformationViewController alloc]init];
                BasicVc.hidesBottomBarWhenPushed = YES;
                BasicVc.savedImage = self.savedImage;
                [self.navigationController pushViewController:BasicVc animated:YES];
                
            }
            if (indexPath.row ==1) {
                
                SettingController *settingVc=[[SettingController alloc]initWithStyle:UITableViewStyleGrouped];
                settingVc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:settingVc animated:YES];
            }
         }
        
        
    }
   
}

//#pragma mark 让分区标题随tableView滚动
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    
//    CGFloat sectionHeaderHeight = 50;
//    
//    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//        
//        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//        
//    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
//        
//        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
//        
//    }
//    
//}


- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSString *)md5HexDigest:(NSString*)password
{
    
    const char *original_str = [password UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(original_str, strlen(original_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
    {
        [hash appendFormat:@"%02X", result[i]];
    }
    NSString *mdfiveString = [hash lowercaseString];
    
//    NSLog(@"Encryption Result = %@",mdfiveString);
    return mdfiveString;
}

@end
